package band.wukong.practice.springboot.boot.web;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

import java.util.ArrayList;
import java.util.List;

/**
 * 各种视图的例子
 *
 * @author wukong(wukonggg@139.com)
 */
@Controller
@SpringBootApplication
public class PersonViewApplication {

    private static final Logger logger = LoggerFactory.getLogger(PersonViewApplication.class);


    public InternalResourceViewResolver defaultViewResolver() {
        return new InternalResourceViewResolver();
    }


    @RequestMapping("/person/thymeleaf")
    public String thymeleaf(Model model) {
        logger.debug("thymeleaf");

        Person single = new Person("Iguana", 2);

        List<Person> persons = new ArrayList<>();
        persons.add(new Person("Cat", 1));
        persons.add(new Person("Goat", 3));
        persons.add(new Person("Elephant", 50));

        model.addAttribute("single", single);
        model.addAttribute("persons", persons);

        return "person-thymeleaf";
    }

    public static void main(String[] args) {
        SpringApplication.run(PersonViewApplication.class, args);
    }
}
